<template>
    <div id="tabGameOption" :style="positionRight">
        <!-- 把手 -->
        <div id="handle" @click="openTables"></div>
        <!-- 桌子列表 -->
        <div class="tables">
            <!-- 桌子 -->
            <div v-for="(A,ak) in RoomTbale" :key=ak>
                <GameOptionSon v-for="(B,k) in A"  :key="k" ref="GameOptionSon" @postMessage="postMessage" :id="{pos:ak,index:k}" ></GameOptionSon>
            </div>
        </div>
    </div>
</template>
<script>
import GameOptionSon from "@/components/GameOptionSon.vue"
export default {
    name:"tabs",
    data(){
		return{
			// 位移控制数据
			positionRight:"",
			workerObj:null,
		}
	},
	computed:{
		RoomTbale(){
			let a=this.$store.getters["RoomStore/tables"];
			return a;
		},
		// 限红
		xh(){
			let b=this.$store.getters.XH;
			let c;
			if(b){
				c=parseInt(Math.min.apply(Math,[b[0][0],b[1][0],b[2][0]]))+"~";
				c+=parseInt(Math.max.apply(Math,[b[0][1],b[1][1],b[2][1]]));
				return c;				
			}
		},
	},
	methods:{
		// 切出换台列表
		openTables(){
			if(!this.positionRight){
				setTimeout(()=>{
					this.$store.dispatch("RoomStore/getPublicTable");
				},600)
			}
			this.positionRight= this.positionRight?"":"right:0px";
		},
		postMessage(msg){
			if(this.workerObj){
				this.workerObj.postMessage(msg);
			}else{
				let a=setInterval(()=>{
					if(this.workerObj){
						this.workerObj.postMessage(msg);
					}
					clearInterval(a);
				},500)
			}
		}
	},
	components:{
		GameOptionSon
	},
	mounted(){
		this.workerObj=new Worker("././assets/js/ludan.js");
		this.workerObj.onmessage=(data)=>{
			let msg=data.data;
			if(msg.id==2){
				this.$refs.GameOptionSon[msg.room].setLudan(msg);
			}
		}
	},
	beforeDestroy(){
		this.workerObj.terminate();
		this.workerObj=null;
	}
}
</script>
